﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.DataVisualization.Charting;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data.OleDb;
using System.Data;

namespace DashBoardInterfaz
{
    public partial class index : System.Web.UI.Page
    {
        public static String _dbSource = "Data Source = localhost;";
        public static String _dbCatalog = "Initial Catalog = ";
        public static String _dbSecurity = ";Integrated Security = True";
        public static String _dbName = "DashBoardDataBase";

        protected void Page_Load(object sender, EventArgs e)
        {
            //ExecuteSql(Chart1);
        }


        public void ExecuteSql(Chart Chart)
        {
            String _conexion = _dbSource + _dbCatalog + _dbName + _dbSecurity;
            using (SqlConnection connection = new SqlConnection(_conexion))
            {
                using (SqlCommand command = new SqlCommand())
                {
                    connection.Open();

                    command.Connection = connection;
                    command.CommandType = System.Data.CommandType.Text;
                    string sql = string.Format("SELECT Rendimiento,HoraTransaccion  FROM InfoBonos");
                    command.CommandText = sql;
                    command.CommandTimeout = 10;

                    SqlDataReader reader = command.ExecuteReader();
                    Chart.DataSource = reader;
                    Chart.Series[0].ChartType = SeriesChartType.Line;
                    

                    Chart.Series.Add("Series 1");
                    Chart.Series["Series 1"].ChartType = SeriesChartType.Line;
                    Chart.Series["Series 1"].BorderWidth = 10;
                    Chart.Series["Series 1"].ToolTip = "#VAL";                    
                    // Set series members names for the X and Y values 
                    Chart.Series["Series 1"].XValueMember = "HoraTransaccion";
                    Chart.Series["Series 1"].YValueMembers = "Rendimiento";

                    // Data bind to the selected data source
                    Chart.DataBind();

                    reader.Close();
                    connection.Close();

                }
            }
        }

    }
}